package Controller.Actions;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class LoginAction implements Action {
    
    private String name;
    
    public LoginAction() 
    {
        this.name = "Login";
    }
    
    public String getName()
    {
        return name;
    }
   
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        StudentModel smodel = new StudentModel();
        String id = request.getParameter("id");
        boolean flag = false;
        
        PersonList list = smodel.search(new Person());
        
        ArrayList array = list.getPersons();
        
        for(int i=0; i<array.size(); i++)
        {
            Person tmp = (Person)array.get(i);
            if(tmp.getId() == Integer.parseInt(id))
            {
                flag = true;
                break;
            }
        } 
        
        if(flag)
        {
            request.setAttribute("id", id);
            RequestDispatcher view = request.getRequestDispatcher("student.jsp");
            view.forward(request, response);
        }
        else 
        {
            RequestDispatcher view = request.getRequestDispatcher("index.jsp");
            view.forward(request, response);
        }
    }
}
